#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QMessageBox>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QTabWidget>
#include<QGraphicsView>
#include<QToolButton>
#include<QToolBar>
#include<QToolBox>
#include<Util/get_setInfo.h>
#include<iostream>
#include "Util/CodeHelper.h"
#include<Util/handlefile.h>
#include<Util/omscodehelper.h>
const int InsertTextButton = 10;
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //设置工程大小
    QDesktopWidget* desktopWidget = QApplication::desktop();
    //得到客户区矩形
    QRect clientRect = desktopWidget->availableGeometry();

    this->setMinimumSize(clientRect.width()*0.65,clientRect.height()*0.7);
    this->setWindowIcon(QIcon(":/QSS/image/Window_Icon.png"));



    //存储工程路径
    QDir  ProjectDir(QApplication::applicationDirPath());

    DirPath=ProjectDir.absolutePath();
    //初始化MdlInfoMap
    MdlInfoMap=new  QMap<QListWidgetItem *,MdlInfo *>();
    //初始化打包界面

    MdlPreviewWidget = new PreView();
    pUI = MdlPreviewWidget->pUI;
    pUI->ChooseModel->setCurrentIndex(2);
    this->ChooseModel_currentIndexChanged(2);

    ui->MainWindowLayout->addWidget(MdlPreviewWidget);

    //初始化表格
    initTable();
    init_statusBar();
    patchMethod=NULL;

    //信号槽连接
    connect(pUI->openOMS,SIGNAL(clicked(bool)),this,SLOT(openOMS_clicked()));
    connect(pUI->ChooseModel,SIGNAL(currentIndexChanged(int)),this,SLOT(ChooseModel_currentIndexChanged(int)));
    connect(pUI->ChooseLibs,SIGNAL(clicked(bool)),this,SLOT(ChooseLibs_clicked()));
    connect(pUI->LibItemsRemove,SIGNAL(clicked(bool)),this,SLOT(LibItemsRemove_clicked()));
    connect(pUI->AddHardwareConItem,SIGNAL(clicked(bool)),this,SLOT(AddHardwareConItem_clicked()));
    connect(pUI->HardConRemove,SIGNAL(clicked(bool)),this,SLOT(HardConRemove_clicked()));
    connect(pUI->AddSoftEnvirItem,SIGNAL(clicked(bool)),this,SLOT(AddSoftEnvirItem_clicked()));
    connect(pUI->SoftEnvirRemove,SIGNAL(clicked(bool)),this,SLOT(SoftEnvirRemove_clicked()));
    connect(pUI->AddSuportResItem,SIGNAL(clicked(bool)),this,SLOT(AddSuportResItem_clicked()));
    connect(pUI->SuportResRemove,SIGNAL(clicked(bool)),this,SLOT(SuportResRemove_clicked()));
    connect(pUI->AddTestDataItem,SIGNAL(clicked(bool)),this,SLOT(AddTestDataItem_clicked()));
    connect(pUI->TestDataRemove,SIGNAL(clicked(bool)),this,SLOT(TestDataRemove_clicked()));
    connect(pUI->GeneratePackage,SIGNAL(clicked(bool)),this,SLOT(GeneratePackage_clicked()));
    connect(pUI->ChooseLicense,SIGNAL(currentIndexChanged(QString)),this,SLOT(ChooseLicense_currentTextChanged(QString)));
    connect(pUI->setConversionMethods,SIGNAL(clicked(bool)),this,SLOT(patchmethod_clicked()));
    connect(MdlPreviewWidget->MdlListWidget,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(ItemsList_itemClicked(QListWidgetItem*)));
    connect(MdlPreviewWidget->MdlListWidget,SIGNAL(clicked(QModelIndex)),this,SLOT(MdlListItemClicked(QModelIndex)));
    connect(MdlPreviewWidget->MdlListWidget,SIGNAL(currentRowChanged(int)),this,SLOT(MdlListWidget_CurrentIndex_changed(int)));
    connect(MdlPreviewWidget,SIGNAL(addItem_clicked()),this,SLOT(addMdl_Clicked()));
    connect(MdlPreviewWidget,SIGNAL(add_mdl_clicked()),this,SLOT(addMdl_Clicked()));
    connect(MdlPreviewWidget,SIGNAL(deleteItem_clicked()),this,SLOT(deleteItem()));
    connect(MdlPreviewWidget,SIGNAL(clearItem_clicked()),this,SLOT(clearItem()));
    connect(pUI,SIGNAL(sendStateInfo(QString)),this,SLOT(showStateinfo(QString)));
    connect(this,SIGNAL(sendInfoStr(QString)),this,SLOT(showStateinfo(QString)));
    connect(MdlPreviewWidget,SIGNAL(toPack_clicked()),this,SLOT(on_actionBuild_Package_triggered()));
    connect(MdlPreviewWidget,SIGNAL(settings_clicked()),this,SLOT(SettingsSchema_clicked()));
    connect(MdlPreviewWidget,SIGNAL(mdlView_clicked()),this,SLOT(on_actionMdl_triggered()));
    connect(MdlPreviewWidget,SIGNAL(methodsView_clicked()),this,SLOT(on_actionMethod_triggered()));

    //connect(pUI,SIGNAL(preview_clicked(int)),this->MainStackLayout,SLOT(setCurrentIndex(int)));
    //最大化显示
    // MainWindow::showMaximized();
    emit sendInfoStr(tr("Initialization complete."));




}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::initDirPath(){
    QDir *temp = new QDir;
    bool exist = temp->exists(DirPath+"/java");
    if(exist) qWarning()<<tr("java has exist.")<<endl;
    else{
        bool ok = temp->mkdir(DirPath+"/java");
        if( ok )  qWarning()<<tr("java  successfully created .")<<endl;
    }
    exist = temp->exists(DirPath+"/wrapper");
    if(exist) qWarning()<<tr("wrapper has exist.")<<endl;
    else{
        bool ok = temp->mkdir(DirPath+"/wrapper");
        if( ok )  qWarning()<<tr("wrapper  successfully created .")<<endl;
    }

    exist = temp->exists(DirPath+"/wrapper/model");
    if(exist) qWarning()<<tr("wrapper/model has exist.")<<endl;
    else{
        bool ok = temp->mkdir(DirPath+"/wrapper/model");
        if( ok ) qWarning()<<tr("wrapper/model successfully created.")<<endl;
    }

    exist = temp->exists(DirPath+"/wrapper/model/libs");
    if(exist) qWarning()<<tr("wrapper/model/libs has exist.")<<endl;
    else{
        bool ok = temp->mkdir(DirPath+"/wrapper/model/libs");
        if( ok ) qWarning()<<tr("wrapper/model/libs successfully created.")<<endl;
    }

    exist = temp->exists(DirPath+"/wrapper/supportive");
    if(exist) qWarning()<<tr("wrapper/supportive has exist.")<<endl;
    else{
        bool ok = temp->mkdir(DirPath+"/wrapper/supportive");
        if( ok ) qWarning()<<tr("wrapper/supportive successfully created.")<<endl;
    }

    exist = temp->exists(DirPath+"/wrapper/testify");
    if(exist) qWarning()<<tr("wrapper/testify has exist.")<<endl;
    else{
        bool ok = temp->mkdir(DirPath+"/wrapper/testify");
        if( ok ) qWarning()<<tr("wrapper/testify successfully created.")<<endl;
    }

}

void MainWindow::init_statusBar(){
    QStatusBar *bar=ui->statusBar;

    first_statusLabel=new QLabel();
    //first_statusLabel->setMinimumSize(150,20);
    bar->addWidget(first_statusLabel);
}

void MainWindow::showStateinfo(QString infoStr){
    first_statusLabel->setText(infoStr);
}

//打开文件
void MainWindow::addMdl_Clicked()
{
    emit sendInfoStr(tr("Ready to open MDL file."));


    //QFileDialog Fdlg=new QFileDialog;
    QString FileName = QFileDialog::getOpenFileName(this,
                                                    tr("Open mdl"), mInitialFolder, tr("MDL files (*.mdl);;XML files (*.xml)"));

    if(!FileName.isEmpty()){
        LoadMdl(FileName);
    }

}

void MainWindow::LoadMdl(QString FileName){
    QList<CState *> * StateList=new QList<CState *>();
    MdlInfo *mdlInfo=new MdlInfo();
    if(this->mInitialFolder==""){
        this->mInitialFolder=QDir(this->ProjectPath).rootPath();
    }
    if(FileName!=NULL){
        if(get_setInfo::getEventInfo(FileName,StateList)){   //获取相关信息
            QListWidgetItem *newItem=new QListWidgetItem();
            newItem->setText(QFileInfo(FileName).baseName());
            MdlPreviewWidget->MdlListWidget->addItem(newItem);

            mdlInfo->setStateInfo(StateList);
            mdlInfo->setMdlFilePath(FileName);

            //readLyoFile
            QString lyofilepath=FileName;
            lyofilepath=lyofilepath.replace(lyofilepath.indexOf('.'),lyofilepath.length()-lyofilepath.indexOf('.'),".lyo");

            QMap<QString,QList<QMap<QString,QString>*>*> *lyoInfo=new QMap<QString,QList<QMap<QString,QString>*>*>();

            if(lyofilepath!=NULL){
                if(!get_setInfo::readLyoFile(lyofilepath,lyoInfo)){
                    lyoInfo=NULL;
                    emit sendInfoStr(tr("LYO File load failed."));
                }
            }
            mdlInfo->setLyoInfo(lyoInfo);     //set lyoInfo
            MdlInfoMap->insert(newItem,mdlInfo);
        }
        QString parentPath =QFileInfo(FileName).dir().absolutePath();
        this->mInitialFolder=parentPath;

        this->MdlPreviewWidget->add_MdlListTab();

        emit sendInfoStr(tr("MDL File successfully loaded."));
    }
    emit sendInfoStr(tr(""));
}

void MainWindow::deleteItem(){
    QMessageBox::StandardButton button;
    button = QMessageBox::question(this, tr("delete Item"),
                                   QString(tr("Sure to delete?")),
                                   QMessageBox::Yes | QMessageBox::No);
    if (button == QMessageBox::No) {
        return ;
    }
    else if (button == QMessageBox::Yes) {
        if(!HandleListWidget::deleteSelectItem(this->MdlPreviewWidget->MdlListWidget,this->MdlInfoMap)){
            return ;
        }
        this->MdlPreviewWidget->scene->clear();
        this->currentMdlPath="";
        this->currentMdlIndex=0;
    }


}

void MainWindow::clearItem(){

    QMessageBox::StandardButton button;
    button = QMessageBox::question(this, tr("clear Items"),
                                   QString(tr("Sure to clear?")),
                                   QMessageBox::Yes | QMessageBox::No);
    if (button == QMessageBox::No) {
        return ;
    }
    else if (button == QMessageBox::Yes) {
        if(!HandleListWidget::ClearItem(this->MdlPreviewWidget->MdlListWidget,this->MdlInfoMap)){
            return ;
        }
        this->currentMdlPath="";
        this->currentMdlIndex=0;
        this->MdlPreviewWidget->scene->clear();
    }
}


void MainWindow::initTable(){
    //初始化依赖文件列表
    pUI->LibNamesTable->setSelectionBehavior(QAbstractItemView::SelectRows);
    pUI->LibNamesTable->setEditTriggers(QAbstractItemView::NoEditTriggers);

    //初始化HardConTable
    //初始化表格
    pUI->HardConTable->setEditTriggers(QAbstractItemView::DoubleClicked);   //表格双击编辑
    pUI->HardConTable->setSelectionBehavior(QAbstractItemView::SelectRows);  //整行选中的方式
    pUI->HardConTable->setColumnWidth(0,120);
    pUI->HardConTable->setAlternatingRowColors(false);
    pUI->HardConTable->setDragEnabled(false);
    //添加条目
    DataUtil *dataUtil=new DataUtil();
    if(!dataUtil->AddEditedRow(pUI->HardConTable,"Memory Size","1G")){
        qWarning()<<"Memory Size set error."<<endl;
        emit sendInfoStr(tr("Memory Size set error."));
        return ;
    }
    if(!dataUtil->AddEditedRow(pUI->HardConTable,"Storage Size","129M")){
        qWarning()<<"Storage Size set error."<<endl;
        emit sendInfoStr(tr("Add failed"));
        return ;
    }

    //初始化SoftEnvirTable
    pUI->SoftEnvirTable->setEditTriggers(QAbstractItemView::DoubleClicked);   //表格双击编辑
    pUI->SoftEnvirTable->setSelectionBehavior(QAbstractItemView::SelectRows);  //整行选中的方式
    pUI->SoftEnvirTable->setColumnWidth(0,120);
    pUI->SoftEnvirTable->setAlternatingRowColors(false);
    pUI->SoftEnvirTable->setDragEnabled(false);

    //初始化TestDataList
    pUI->TestDataList->setEditTriggers(QAbstractItemView::NoEditTriggers);   //禁止表格编辑
    pUI->TestDataList->setSelectionBehavior(QAbstractItemView::SelectRows);  //整行选中的方式
    pUI->TestDataList->setColumnWidth(0,120);
    pUI->TestDataList->setAlternatingRowColors(false);
    pUI->TestDataList->setDragEnabled(false);

    //初始化SuportResList
    pUI->SuportResList->setEditTriggers(QAbstractItemView::NoEditTriggers);   //禁止表格编辑
    pUI->SuportResList->setSelectionBehavior(QAbstractItemView::SelectRows);  //整行选中的方式
    pUI->SuportResList->setColumnWidth(0,120);
    pUI->SuportResList->setAlternatingRowColors(false);
    pUI->SuportResList->setDragEnabled(false);

    //初始化inputDialog
    inputDialog=new InputDialog();
    inputDialog->setModal(true); //总在最前
    connect(inputDialog,SIGNAL(sendDataList(QList<QString>*)),this,SLOT(ReceiveData(QList<QString>*)));
    //初始化License Area
    this->ChooseLicense_currentTextChanged("Apache Licence 2.0");

}

//create oms wraper fold
bool MainWindow::initOmsWraperPath(){
    QDir *temp = new QDir;
    bool exist = temp->exists(DirPath+"/omsWraper");
    if(exist) qWarning()<<tr("omsWraper has exist.")<<endl;
    else{
        bool ok = temp->mkdir(DirPath+"/omsWraper");
        if( ok )  qWarning()<<tr("omsWraper  successfully created .")<<endl;
        else return false;
    }
    exist = temp->exists(DirPath+"/java");
    if(exist) qWarning()<<tr("java has exist.")<<endl;
    else{
        bool ok = temp->mkdir(DirPath+"/java");
        if( ok )  qWarning()<<tr("java  successfully created .")<<endl;
    }
    exist = temp->exists(DirPath+"/omsWraper/model");
    if(exist) qWarning()<<tr("/omsWraper/model has exist.")<<endl;
    else{
        bool ok = temp->mkdir(DirPath+"/omsWraper/model");
        if( ok )  qWarning()<<tr("omsWraper/model  successfully created .")<<endl;
        else return false;
    }
    exist = temp->exists(DirPath+"/omsWraper/model/libs");
    if(exist) qWarning()<<tr("omsWraper/model/libs has exist.")<<endl;
    else{
        bool ok = temp->mkdir(DirPath+"/omsWraper/model/libs");
        if( ok )  qWarning()<<tr("omsWraper/model/libs  successfully created .")<<endl;
        else return false;
    }

    exist = temp->exists(DirPath+"/omsWraper/model/oms");
    if(exist) qWarning()<<tr("omsWraper/model/oms has exist.")<<endl;
    else{
        bool ok = temp->mkdir(DirPath+"/omsWraper/model/oms");
        if( ok )  qWarning()<<tr("omsWraper/model/oms  successfully created .")<<endl;
        else return false;
    }
    exist = temp->exists(DirPath+"/omsWraper/model/oms/3.1");
    if(exist) qWarning()<<tr("omsWraper/model/oms/3.1 has exist.")<<endl;
    else{
        bool ok = temp->mkdir(DirPath+"/omsWraper/model/oms/3.1");
        if( ok )  qWarning()<<tr("omsWraper/model/oms/3.1  successfully created .")<<endl;
        else return false;
    }
    exist = temp->exists(DirPath+"/omsWraper/model/oms/3.2");
    if(exist) qWarning()<<tr("omsWraper/model/oms/3.2 has exist.")<<endl;
    else{
        bool ok = temp->mkdir(DirPath+"/omsWraper/model/oms/3.2");
        if( ok )  qWarning()<<tr("omsWraper/model/oms/3.2  successfully created .")<<endl;
        else return false;
    }
    exist = temp->exists(DirPath+"/omsWraper/model/oms/workdir");
    if(exist) qWarning()<<tr("omsWraper/model/oms/workdir has exist.")<<endl;

    else{
        bool ok = temp->mkdir(DirPath+"/omsWraper/model/oms/workdir");
        if( ok )  qWarning()<<tr("omsWraper/model/oms/workdir  successfully created .")<<endl;
        else return false;
    }
    exist = temp->exists(DirPath+"/omsWraper/supportive");
    if(exist) qWarning()<<tr("omsWraper/supportive has exist.")<<endl;
    else{
        bool ok = temp->mkdir(DirPath+"/omsWraper/supportive");
        if( ok )  qWarning()<<tr("omsWraper/supportive  successfully created .")<<endl;
        else return false;
    }

    exist = temp->exists(DirPath+"/omsWraper/testify");
    if(exist) qWarning()<<tr("omsWraper/testify has exist.")<<endl;
    else{
        bool ok = temp->mkdir(DirPath+"/omsWraper/testify");
        if( ok )  qWarning()<<tr("omsWraper/testify  successfully created .")<<endl;
        else return false;
    }

    //拷贝工程
    if(!copyDirFiles(ProjectPath,DirPath+"/omsWraper/model/oms/workdir",true)){
        emit sendInfoStr(tr("Copy file failed！"));
        return false;
    }
    //拷贝OMS、UNX平台依赖jar包
    if(!copyDirFiles(DirPath+"/templates/libs/OMS",DirPath+"/omsWraper/model/libs",true)){
        emit sendInfoStr(tr("Copy file failed！"));
        return false;
    }
    //拷贝dll
    if(!copyDirFiles(DirPath+"/templates/dll/OMS",DirPath+"/omsWraper/model",true)){
        emit sendInfoStr(tr("Copy file failed！"));
        return false;
    }
    //将mdl之类的拷贝（以后再通过添加修改来弄）
    if(!copyDirFiles(DirPath+"/templates/mdl",DirPath+"/omsWraper/model",true)){
        emit sendInfoStr(tr("Copy file failed！"));
        return false;
    }
    //这里是拷贝，往后再做修改保存
    if(!copyDirFiles(DirPath+"/templates/packageConfig",DirPath+"/omsWraper",true)){
        emit sendInfoStr(tr("Copy file failed！"));
        return false;
    }
    //拷贝omshome
    if(!copyDirFiles(DirPath+"/templates/templateFiles/OMS/3.1",DirPath+"/omsWraper/model/oms/3.1",true)){
        emit sendInfoStr(tr("Copy file failed！"));
        return false;
    }

    if(!copyDirFiles(DirPath+"/templates/templateFiles/OMS/3.2",DirPath+"/omsWraper/model/oms/3.2",true)){
        emit sendInfoStr(tr("Copy file failed！"));
        return false;
    }

    return true;
}

void MainWindow::openOMS_clicked()
{
    //弹出对话框，用户选择OMS工程目录
    if(this->CurrentType==1){
        emit sendInfoStr(tr("Add OMS project..."));
        ProjectPath = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
                                                        "/home",
                                                        QFileDialog::ShowDirsOnly
                                                        | QFileDialog::DontResolveSymlinks);
        if(ProjectPath!=""){
            pUI->ProjectPath->setText(ProjectPath);
            emit sendInfoStr(tr("OMS Project file successfully loaded."));
        }else{
            emit sendInfoStr(tr(""));
        }
    }else if(this->CurrentType==2){
        emit sendInfoStr(tr("Choose EXE..."));
        ProjectPath =  QFileDialog::getOpenFileName(this,
                                                    tr("Choose EXE"), "", tr("EXE (*.exe);;All files (*.*)"));
        if(ProjectPath!=""){
            pUI->ProjectPath->setText(ProjectPath);

            pUI->ProjectRelativePath->setText("./"+QDir(ProjectPath).dirName());
            emit sendInfoStr(tr("EXE file successfully loaded."));
        }else{
            emit sendInfoStr(tr(""));
        }

    }



}

void MainWindow::ItemsList_itemClicked(QListWidgetItem *item)
{
    MdlInfo *ClickedItem = MdlInfoMap->value(item);
    if(ClickedItem==NULL){
        return;
    }
    currentMdlPath=ClickedItem->getMdlFilePath();

    currentStateList=ClickedItem->getStateInfo();
    CurrentItem = item;
    showScene(item);
    this->MdlPreviewWidget->add_MdlView();

    patchMethod=new PatchMethod(this->MdlInfoMap);
    patchMethod->initUI(currentStateList);
    patchMethod->ShowCustomScene(CurrentItem);


    connect(patchMethod,SIGNAL(SendDCCInfo(QMap<int,DCCInfo*>*)),this,SLOT(getDCCInfo(QMap<int,DCCInfo*>*)));




}

void MainWindow::MdlListItemClicked(QModelIndex mModelIndex){
    this->currentMdlIndex = mModelIndex.row ();
}

void MainWindow::MdlListWidget_CurrentIndex_changed(int index){
    this->currentMdlIndex = index;
}

void MainWindow::showScene(QListWidgetItem *item){
    MdlPreviewWidget->scene->clear();
    MdlPreviewWidget->scene->addAllInfo(MdlInfoMap->value(item)->getStateInfo());

    if(MdlInfoMap->value(item)->getLyoInfo()==NULL){
        emit showStateinfo(tr("have no lyo info."));
        return;
    }
    QMapIterator<QString,QList<QMap<QString,QString>*>*> i(*MdlInfoMap->value(item)->getLyoInfo());
    while(i.hasNext()){
        i.next();
        if(i.key()=="Activitys"){

            QList<QMap<QString,QString>*> *Activitys=MdlInfoMap->value(item)->getLyoInfo()->value(i.key());
            for(int index=0;index<Activitys->count();index++){
                MdlPreviewWidget->scene->addProcessItem(*Activitys->at(index));
            }
        }
        if(i.key()=="Rules"){
            QList<QMap<QString,QString>*> *Rules=MdlInfoMap->value(item)->getLyoInfo()->value(i.key());
            for(int index=0;index<Rules->count();index++){

                MdlPreviewWidget->scene->addArrowItem(*Rules->at(index));

            }
        }
    }
}

void MainWindow::ChooseModel_currentIndexChanged(int index)
{
    this->CurrentType=index;
    switch (index) {
    case 0:
        pUI->openOMS->setText(tr("Add OMS"));
        pUI->openOMS->setEnabled(false);
        pUI->openOMS->setVisible(false);
        pUI->ProjectPath->setEnabled(false);
        pUI->ProjectPath->setVisible(false);
        pUI->projectPathLabel->setVisible(false);
        pUI->ProjectRelativePathLabel->setVisible(false);
        pUI->ProjectRelativePath->setVisible(false);

        break;
    case 1:
        pUI->openOMS->setText(tr("Add OMS"));
        pUI->projectPathLabel->setText(tr("OMS project path"));
        pUI->projectPathLabel->setVisible(true);
        pUI->openOMS->setEnabled(true);
        pUI->openOMS->setVisible(true);
        pUI->ProjectPath->setEnabled(true);
        pUI->ProjectPath->setVisible(true);
        pUI->ProjectRelativePathLabel->setVisible(true);
        pUI->ProjectRelativePath->setVisible(true);
        break;
    case 2:
        pUI->openOMS->setText(tr("Add EXE"));
        pUI->projectPathLabel->setText(tr("EXE File Path"));
        pUI->projectPathLabel->setVisible(true);
        pUI->openOMS->setEnabled(true);
        pUI->openOMS->setVisible(true);
        pUI->ProjectPath->setEnabled(true);
        pUI->ProjectPath->setVisible(true);
        pUI->ProjectRelativePathLabel->setVisible(true);
        pUI->ProjectRelativePath->setVisible(true);
        break;
    default:
        break;
    }

}

void MainWindow::ChooseLibs_clicked()
{
    emit sendInfoStr(tr("Ready to add dependent file."));
    //选取的lib文件名+其路径

    FileOrFold *fileOrFold = new FileOrFold(tr("Do you want to add file or fold?"));
    fileOrFold->show();
    if(fileOrFold->exec()==QDialog::Accepted){
        QStringList files_full;
        if(this->mInitialFolder==""){
            this->mInitialFolder=QDir(this->ProjectPath).rootPath();
        }
        if(fileOrFold->getType()=="FILE"){
            //弹出对话框

            files_full = QFileDialog::getOpenFileNames(this,
                                                       tr("Choose File"), mInitialFolder, tr("DLL (*.dll);;All files (*.*)"));


        }else{

            QFileDialog fileDlg( this, tr("Please select folder"), mInitialFolder );
            fileDlg.setFileMode(QFileDialog::DirectoryOnly);
            fileDlg.setOption(QFileDialog::DontUseNativeDialog,true);
            QListView *listView = fileDlg.findChild<QListView*>("listView");
            if (listView)
                listView->setSelectionMode(QAbstractItemView::ExtendedSelection);
            QTreeView *treeView = fileDlg.findChild<QTreeView*>();
            if (treeView)
                treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
            if(fileDlg.exec())
            {
                files_full = fileDlg.selectedFiles();
            }

        }

        emit sendInfoStr(tr(""));
        if(!files_full.isEmpty()){
            DataUtil *dataUtil=new DataUtil();
            if(!dataUtil->AddItemToTable(pUI->LibNamesTable,files_full)){
                emit sendInfoStr(tr("Loading dependent file error."));
                return;
            }
            QString parentPath =QFileInfo(files_full.at(0)).dir().absolutePath();
            this->mInitialFolder=parentPath;
            emit sendInfoStr(tr("Dependent file successfully loaded."));
        }
    }
    emit sendInfoStr(tr(""));


}

void MainWindow::LibItemsRemove_clicked()
{

    DataUtil *dataUtil=new DataUtil();
    dataUtil->Remove(pUI->LibNamesTable);

}

void MainWindow::LockLibsTable_clicked()
{
    if(pUI->LibNamesTable->dragEnabled()==true){
        pUI->LibNamesTable->setDragEnabled(false);
        pUI->LibItemsRemove->setEnabled(false);
        pUI->ChooseLibs->setEnabled(false);
    }else{
        pUI->LibNamesTable->setEnabled(true);
        pUI->LibNamesTable->setDragEnabled(true);
        pUI->LibItemsRemove->setEnabled(true);
        pUI->ChooseLibs->setEnabled(true);
    }
}

//添加Hardware Condition
void MainWindow::AddHardwareConItem_clicked()
{
    inputDialog->show();
    inputDialog->exec();
    if(inputDialog->Accepted==QDialog::Accepted){
        DataUtil *dataUtil=new DataUtil();
        dataUtil->AddEditedRow(pUI->HardConTable,inputDataList->at(0),inputDataList->at(1));
    }
}

void MainWindow::HardConRemove_clicked()
{
    DataUtil *dataUtil=new DataUtil();
    dataUtil->Remove(pUI->HardConTable);
}

void MainWindow::getDCCInfo(QMap<int, DCCInfo *> *dCCInfoMap){
    this->DCCInfoMap=dCCInfoMap;



}

void MainWindow::AddSoftEnvirItem_clicked()
{
    inputDialog->show();
    inputDialog->exec();
    if(inputDialog->Accepted==QDialog::Accepted){
        DataUtil *dataUtil=new DataUtil();
        dataUtil->AddEditedRow(pUI->SoftEnvirTable,inputDataList->at(0),inputDataList->at(1));
    }
}

void MainWindow::SoftEnvirRemove_clicked()
{
    DataUtil *dataUtil=new DataUtil();
    dataUtil->Remove(pUI->SoftEnvirTable);
}

void MainWindow::AddTestDataItem_clicked()
{
    emit sendInfoStr(tr("Loading test  file."));
    //选取的lib文件名+其路径
    QStringList files_full;
    //弹出对话框
    files_full = QFileDialog::getOpenFileNames(this,
                                               tr("Choose File"), "", tr("XML (*.xml);;All files (*.*)"));

    emit sendInfoStr(tr("Selecting file..."));

    if(!files_full.isEmpty()){

        DataUtil *dataUtil=new DataUtil();
        if(!dataUtil->AddItemToTable(pUI->TestDataList,files_full)){
            emit sendInfoStr(tr("File load failed."));
            return;
        }

        emit sendInfoStr(tr("File loaded successfully."));
    }
    emit sendInfoStr(tr(""));
}

void MainWindow::TestDataRemove_clicked()
{
    DataUtil *dataUtil=new DataUtil();
    dataUtil->Remove(pUI->TestDataList);
}

void MainWindow::AddSuportResItem_clicked()
{
    emit sendInfoStr(tr("Loading Suport Resource..."));
    FileOrFold *fileOrFold = new FileOrFold(tr("Do you want to add file or fold?"));
    fileOrFold->show();
    if(fileOrFold->exec()==QDialog::Accepted){
        QStringList files_full;
        if(this->mInitialFolder==""){
            this->mInitialFolder=QDir(this->ProjectPath).rootPath();
        }
        if(fileOrFold->getType()=="FILE"){


            //弹出对话框
            files_full = QFileDialog::getOpenFileNames(this,
                                                       tr("Choose File"), mInitialFolder, tr("EXE(*.exe);;bat File (*.bat);;All files (*.*)"));

        }else if(fileOrFold->getType()=="FOLD"){

            QFileDialog fileDlg( this, tr("Please select folder"), mInitialFolder );
            fileDlg.setFileMode(QFileDialog::DirectoryOnly);
            fileDlg.setOption(QFileDialog::DontUseNativeDialog,true);
            QListView *listView = fileDlg.findChild<QListView*>("listView");
            if (listView)
                listView->setSelectionMode(QAbstractItemView::ExtendedSelection);
            QTreeView *treeView = fileDlg.findChild<QTreeView*>();
            if (treeView)
                treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
            if(fileDlg.exec())
            {
                files_full = fileDlg.selectedFiles();
            }
        }
        DataUtil *dataUtil=new DataUtil();
        if(!dataUtil->AddItemToTable(pUI->SuportResList,files_full)){
            emit sendInfoStr(tr("DLL File load failed."));
            return;
        }
        QString parentPath =QFileInfo(files_full.at(0)).dir().absolutePath();
        this->mInitialFolder=parentPath;
        emit sendInfoStr(tr("DLL File loaded successfully."));
    }
    emit sendInfoStr(tr(""));
}

void MainWindow::SuportResRemove_clicked()
{
    DataUtil *dataUtil=new DataUtil();
    dataUtil->Remove(pUI->SuportResList);
}

//接收输入框来的参数，写入到table中
void MainWindow::ReceiveData(QList<QString> *inputData){
    inputDataList=inputData;
}

void MainWindow::ChooseLicense_currentTextChanged(const QString &arg1)
{
    QString tempPath;
    tempPath=DirPath+"\\templates\\license\\"+arg1+".txt";
    QFile file(tempPath);
    if(!file.open(QIODevice::ReadWrite | QIODevice::Text)){
        qWarning()<<"Failed to open PathUtil.java"<<endl;
        pUI->LicenseTextArea->setText("");
    }
    QString str(file.readAll());
    file.close();
    pUI->LicenseTextArea->setText(str);
}

void MainWindow::GeneratePackage_clicked()
{

    if(currentMdlPath==""){
        emit sendInfoStr(tr("No files are loaded."));
        return ;
    }
    if(pUI->ChooseModel->currentIndex()==0){


        this->otherPackaged();
    }
    //OMS
    else if(pUI->ChooseModel->currentIndex()==1){


        this->omsPackaged();
    }else if(pUI->ChooseModel->currentIndex()==2){
        this->ExePackaged();
    }
}

void MainWindow::patchmethod_clicked(){
    if(this->currentMdlPath.isEmpty()){
        emit sendInfoStr(tr("No files are loaded or selected."));
        return;
    }

    patchMethod->show();
}

void MainWindow::otherPackaged(){
    emit sendInfoStr(tr("Generating code..."));
    //创建需要的文件夹
    this->initDirPath();
    //拷贝lib包
    if(!copyDirFiles(DirPath+"/templates/libs/Slope",DirPath+"/wrapper/model/libs",true)){
        first_statusLabel->setText("File copy failed.");
        return ;
    }

    //将mdl之类的拷贝（这里先拷贝，以后再通过添加修改来弄）
    if(!copyFileToPath(currentMdlPath,DirPath+"/wrapper/model/"+QFileInfo(currentMdlPath).fileName(),true)){
        first_statusLabel->setText("File copy failed.");
        return ;
    }
    //将页面上的设置信息写入到拷贝的mdl中

    DataUtil *dataUtil=new DataUtil();

    //拷贝依赖文件,testData、suport Resource

    if(!dataUtil->copySpecialFile(pUI->LibNamesTable,DirPath+"/wrapper/model")) {
        first_statusLabel->setText("File copy failed.");
        return;
    }

    if(!dataUtil->copySpecialFile(pUI->TestDataList,DirPath+"/wrapper/testify")) {
        first_statusLabel->setText("File copy failed.");
        return;
    }
    if(!dataUtil->copySpecialFile(pUI->SuportResList,DirPath+"/wrapper/supportive")){
        first_statusLabel->setText("File copy failed.");
        return;
    }
    QMap<QString,QList<QString>*> *InsertMap=new QMap<QString,QList<QString>* >();
    //libList
    InsertMap->insert("LibraryConfigures",dataUtil->getAllTableData(pUI->LibNamesTable));
    //HardConTable
    InsertMap->insert("HardwareConfigures",dataUtil->getAllTableData(pUI->HardConTable));
    //SoftEnvirTable
    InsertMap->insert("SoftwareConfigures",dataUtil->getAllTableData(pUI->SoftEnvirTable));
    //SuportResList
    InsertMap->insert("SupportConfigures",dataUtil->getAllTableData(pUI->SuportResList));
    get_setInfo::addMdlNode(DirPath+"/wrapper/model/"+QFileInfo(currentMdlPath).fileName(),InsertMap);


    //----------------拷贝dll,这里全部拷贝(测试使用)
    if(!copyDirFiles(DirPath+"/templates/dll/Slope",DirPath+"/wrapper/model",true)){
        first_statusLabel->setText("File copy failed.");
        return ;
    }



    //这里是直接拷贝，往后再做修改保存
    if(!copyDirFiles(DirPath+"/templates/packageConfig",DirPath+"/wrapper",true)){
        first_statusLabel->setText("File copy failed.");
        return ;
    }

    CodeHelper* helper = new CodeHelper();
    //helper初始化
    helper->init(this,"",pUI->ModelLibs->text(),DirPath);

    //读取Main.java
    if(!helper->readMainCode(EInputDataType::ASCIIGRID)){
        first_statusLabel->setText("File copy failed.");
        return;
    }

    //读取ModelPackHandle
    if(!helper->readModelHandleCode()){
        first_statusLabel->setText("Read File error.");
        return;
    }

    //生成清单文件
    if(!helper->readMainfest()){
        first_statusLabel->setText("File generation failed.");
        return;
    }

    //生成编译文件
    if(!helper->readCompileBatFile()){
        first_statusLabel->setText("File generation failed.");
        return;
    }

    //获取license
    if(!helper->getLicense(pUI->LicenseTextArea->toPlainText())) {
        first_statusLabel->setText("Failed to get license file.");
        return;
    }
    //编译
    if(!helper->otherCompile()){
        first_statusLabel->setText("Failed to compile java code.");
        return;
    }

    emit sendInfoStr(tr("Java code compiled through."));
    //拷贝生成的jar包
    if(!copyFileToPath(DirPath+"/JavaTemp/slope2.jar",DirPath+"/wrapper/model/slope2.jar",true)){
        first_statusLabel->setText("File copy failed.Please check java home path.");
        return;
    }

    emit sendInfoStr(tr("Saving zip, specifying name..."));
    switch(helper->otherPackaged()){
    case -1:
        emit sendInfoStr(tr("Package failed"));
        break;
    case 0:
        emit sendInfoStr(tr("Package successfully, but failed to delete temporary folder!"));
        break;
    case 1:
        emit sendInfoStr(tr("Package successfully."));
        break;
    }
}

void MainWindow::omsPackaged(){
    if(pUI->ProjectPath->text()==""){
        emit sendInfoStr(tr("Please add  OMS project."));
        return;
    }

    if(!initOmsWraperPath()) {
        first_statusLabel->setText("Packing environment initialization failed!");
        return;
    }


    emit sendInfoStr(tr("Generating OMS package java code..."));
    omsCodeHelper* helper = new omsCodeHelper();

    QString simName="hello.sim";
    QString inputFileName="AA.hdr";
    QString outPutFileName="out.jpg";
    helper->init(this,"ModelRun",DirPath,simName,inputFileName,outPutFileName,"");

    //读取Main.java
    if(!helper->readMain()) {
        emit sendInfoStr(tr("Read File error."));
        return;
    }

    //readUtils
    if(!helper->readUtils()){
        emit sendInfoStr(tr("Read File error."));
        return;
    }

    //生成清单文件
    if(!helper->readManifest()){
        emit sendInfoStr(tr("File generation failed."));
        return;
    }
    //生成编译文件
    if(!helper->readCompile()){
        emit sendInfoStr(tr("File generation failed."));
        return;
    }

    //获取license
    if(!helper->getLicense(pUI->LicenseTextArea->toPlainText())){
        emit sendInfoStr(tr("Failed to get license file."));
        return;
    }

    DataUtil *dataUtil=new DataUtil();

    //将mdl之类的拷贝（这里先拷贝，以后再通过添加修改来弄）
    if(!copyFileToPath(currentMdlPath,DirPath+"/omsWraper/model/"+QFileInfo(currentMdlPath).fileName(),true)){
        first_statusLabel->setText("File copy failed.");
        return ;
    }
    //拷贝依赖文件,testData、suport Resource

    if(!dataUtil->copySpecialFile(pUI->LibNamesTable,DirPath+"/omsWraper/model")) {
        first_statusLabel->setText("File copy failed.");
        return;
    }

    if(!dataUtil->copySpecialFile(pUI->TestDataList,DirPath+"/omsWraper/testify")) {
        first_statusLabel->setText("File copy failed.");
        return;
    }
    if(!dataUtil->copySpecialFile(pUI->SuportResList,DirPath+"/omsWraper/supportive")){
        first_statusLabel->setText("File copy failed.");
        return;
    }
    QMap<QString,QList<QString>*> *InsertMap=new QMap<QString,QList<QString>* >();
    //libList
    InsertMap->insert("LibraryConfigures",dataUtil->getAllTableData(pUI->LibNamesTable));
    //HardConTable
    InsertMap->insert("HardwareConfigures",dataUtil->getAllTableData(pUI->HardConTable));
    //SoftEnvirTable
    InsertMap->insert("SoftwareConfigures",dataUtil->getAllTableData(pUI->SoftEnvirTable));
    //SuportResList
    InsertMap->insert("SupportConfigures",dataUtil->getAllTableData(pUI->SuportResList));
    get_setInfo::addMdlNode(DirPath+"/omsWraper/model/"+QFileInfo(currentMdlPath).fileName(),InsertMap);

    //编译
    if(!helper->omsCompile()) {
        emit sendInfoStr(tr("OMS project package code compiler fails！"));
        return;
    }
    qDebug() << "code compile sucess." <<endl;

    emit sendInfoStr(tr("OMS project package code compiler through."));
    //拷贝生成的jar包
    if(!copyFileToPath(DirPath+"/OMSTemp/Rs.jar",DirPath+"/omsWraper/model/Rs.jar",true)){
        return ;
    }
    emit sendInfoStr(tr("Saving zip, specifying name..."));
    switch(helper->omsPackage()){
    case -1:
        emit sendInfoStr(tr("Package failed."));
        break;
    case 0:
        emit sendInfoStr(tr("Package successfully, but failed to delete temporary folder!"));
        break;
    case 1:
        emit sendInfoStr(tr("Package successfully！"));
        break;
    }
}

void MainWindow::ExePackaged(){

    if(pUI->ProjectPath->text().isEmpty()){
        emit sendInfoStr(tr("you should add  EXE file."));
        return ;
    }
    QString mProjectPath = pUI->ProjectPath->text();
    if(pUI->ProjectRelativePath->text().isEmpty()){
        emit sendInfoStr(tr("you should the relative path of input EXE file."));
        return ;
    }
    QString mProjectRelativePath = pUI->ProjectRelativePath->text();
    if(currentMdlPath.isEmpty()){
        emit sendInfoStr(tr("you haven't choose mdl."));
        return;
    }
    if(this->DCCInfoMap==NULL){
        qWarning()<<"DCCInfoMap has no value."<<endl;
        emit sendInfoStr(tr("you haven't config event and schema."));
        return ;

    }
    QString JarName = "ModelRun";
    mPrePackage = new PrePackage(pUI,this->DirPath);
    ExePackHelper *mExePackHelper = new ExePackHelper(pUI,
                                                      mPrePackage,
                                                      this->currentMdlPath,
                                                      mProjectPath,
                                                      mProjectRelativePath,
                                                      this->DCCInfoMap,
                                                      JarName);
    pUI->GeneratePackage->setEnabled(false);
    connect(mExePackHelper,SIGNAL(sendInfoStr(QString)),this,SLOT(showStateinfo(QString)));
    connect(mExePackHelper,SIGNAL(open_Zip_window()),this,SLOT(showZipDialog()));
    mExePackHelper->start();
    if(mExePackHelper->isFinished()){
        emit sendInfoStr(tr("package finish."));
    }else{
        emit sendInfoStr(tr("package error."));
    }
}

void MainWindow::showZipDialog(){
    QString fileName = QFileDialog::getSaveFileName(pUI,
                                                    QObject::tr("Save Zip"),
                                                    "",
                                                    QObject::tr("Zip Files (*.zip)"));


    if(mPrePackage->PreZip(fileName)){
        emit sendInfoStr(tr("Package successfully！"));
    }else{
        emit sendInfoStr(tr("Package error."));
        return ;
    }
}

void MainWindow::SettingsSchema_clicked()
{
    mSchemaSettings = new SchemaSettings(this->DirPath);
    mSchemaSettings->show();

    if(mSchemaSettings->exec()==QDialog::Accepted){
        if(this->currentMdlPath!=""){
            patchMethod=new PatchMethod(this->MdlInfoMap);
            patchMethod->initUI(currentStateList);
            patchMethod->ShowCustomScene(CurrentItem);
        }
        this->MdlPreviewWidget->refreshMethodList();
    }
    connect(patchMethod,SIGNAL(SendDCCInfo(QMap<int,DCCInfo*>*)),this,SLOT(getDCCInfo(QMap<int,DCCInfo*>*)));
    connect(this->mSchemaSettings,SIGNAL(SendInfo(QString)),this,SLOT(showStateinfo(QString)));

}

void MainWindow::on_actionOpen_Mdl_triggered()
{
    this->addMdl_Clicked();
}

void MainWindow::on_actionConfigure_Convertion_Tools_triggered()
{
    SettingsSchema_clicked();
}

void MainWindow::on_actionBuild_Package_triggered()
{
    MdlPreviewWidget->add_PackView();
}

void MainWindow::on_actionMdl_triggered()
{
    MdlPreviewWidget->add_MdlListTab();
}

void MainWindow::on_actionMethod_triggered()
{
    MdlPreviewWidget->add_MethodListTab();
}

void MainWindow::on_actionLoad_Project_triggered()
{

    QString fileName = QFileDialog::getOpenFileName(this,
                                               tr("Choose Project File"), mInitialFolder, tr("Project File(*.xml);;All files (*.*)"));
   if(fileName.isEmpty()) return;
    ProjectHandle *mProjectHandle = new ProjectHandle();


    if(mProjectHandle->LoadFromFile(fileName)){

        //set mdl list
        this->MdlPreviewWidget->MdlListWidget->clear();
        for(int i=0;i<mProjectHandle->getMdlFileCount();i++){
            this->LoadMdl(mProjectHandle->getMdlFilePath(i));
        }
        this->MdlPreviewWidget->MdlListWidget->setCurrentRow(mProjectHandle->getCurrentMdlIndex());
        this->ItemsList_itemClicked(this->MdlPreviewWidget->MdlListWidget->item(mProjectHandle->getCurrentMdlIndex()));

        //ModelType
        for(int i=0;i<pUI->ChooseModel->count();i++){
            if(pUI->ChooseModel->itemText(i)==mProjectHandle->getModelType()){
                pUI->ChooseModel->setCurrentIndex(i);
                break;
            }
        }
        //Model File and relative path
        pUI->ProjectPath->setText(mProjectHandle->getModelFilePath());
        pUI->ProjectRelativePath->setText(mProjectHandle->getModelFileRelativePath());
        pUI->ModelInputParameter->setText(mProjectHandle->getInputParameter());

        //setMethod
        for(int i=0;i<mProjectHandle->getEventCount();i++){
            this->patchMethod->setMethod(mProjectHandle->getEvent(i)->getEventName(),
                                         mProjectHandle->getEvent(i)->getMethodFilePath(),
                                         mProjectHandle->getEvent(i)->getDataFilePath());
        }

        //set Lib
        pUI->LibNamesTable->setRowCount(0);
        DataUtil *mDataUtil = new DataUtil();
        for(int i=0;i<mProjectHandle->getLibraryCount();i++){

           mDataUtil->AddItemToTable(pUI->LibNamesTable,mProjectHandle->getLibrary(i));
        }

        //set hardware
        pUI->HardConTable->setRowCount(0);
        QMapIterator<QString, QString> HardwareMap(*mProjectHandle->getHardwareCondition());
        while(HardwareMap.hasNext()){
            HardwareMap.next();

            mDataUtil->AddEditedRow(pUI->HardConTable,HardwareMap.key(),HardwareMap.value());
        }
        //set software
        pUI->SoftEnvirTable->setRowCount(0);
        QMapIterator<QString, QString> SoftwareMap(*mProjectHandle->getSoftwareEnvironment());
        while(SoftwareMap.hasNext()){
            SoftwareMap.next();
            mDataUtil->AddEditedRow(pUI->SoftEnvirTable,SoftwareMap.key(),SoftwareMap.value());
        }

        //set testify
        pUI->TestDataList->setRowCount(0);
        for(int i=0;i<mProjectHandle->getTestifyPathCount();i++){
            mDataUtil->AddItemToTable(pUI->TestDataList,mProjectHandle->getTestifyPath(i));
        }

        //set supportive
        pUI->SuportResList->setRowCount(0);
        for(int i=0;i<mProjectHandle->getSupportivePathCount();i++){
            mDataUtil->AddItemToTable(pUI->SuportResList,mProjectHandle->getSupportivePath(i));
        }

        //set License
        pUI->ChooseLicense->setCurrentText(mProjectHandle->getLicenseName());








    }else{
        return ;
    }
}

void MainWindow::on_actionSave_Project_triggered()
{
    ProjectHandle *mProjectHandle = new ProjectHandle();

    //mdlList
    mProjectHandle->setCurrentMdlIndex (this->currentMdlIndex);
    for(int i=0;i<this->MdlInfoMap->count ();i++){
        mProjectHandle->addMdlFilePath (this->MdlInfoMap->value (
                                            this->MdlPreviewWidget->MdlListWidget->item (i))->getMdlFilePath ());
    }

    //ModelEntrance
    mProjectHandle->setModelType (pUI->ChooseModel->currentText ());

    if(this->DCCInfoMap!=NULL){
        QMapIterator<int,DCCInfo *> i(*this->DCCInfoMap);
        while (i.hasNext()) {
            i.next();

            Event *mEvent=new Event();
            mEvent->setEventName (i.value ()->getEventName ());
            mEvent->setMethodFilePath (i.value ()->getMethodFold ());
            mEvent->setDataFilePath (i.value ()->getFileRelativePath ());
            mProjectHandle->addEvent (mEvent);
        }
    }
    //ModelPath
    if(!pUI->ProjectPath->text().isEmpty()){
        mProjectHandle->setModelFilePath(pUI->ProjectPath->text());
    }
    //ModelRelativePath
    if(!pUI->ProjectRelativePath->text().isEmpty()){
        mProjectHandle->setModelFileRelativePath(pUI->ProjectRelativePath->text());
    }

    //InputParameter
    if(!pUI->ModelInputParameter->text().isEmpty()){
        mProjectHandle->setInputParameter(pUI->ModelInputParameter->text());
    }

    //ModelLibrary
    for(int i=0;i<pUI->LibNamesTable->rowCount();i++){
        mProjectHandle->addLibrary(pUI->LibNamesTable->item(i,1)->text());
    }

    //Hardware
    for(int i=0;i<pUI->HardConTable->rowCount();i++){
        mProjectHandle->addHardwareCondition(pUI->HardConTable->item(i,0)->text(),pUI->HardConTable->item(i,1)->text());
    }
    //Software
    for(int i=0;i<pUI->SoftEnvirTable->rowCount();i++){
        mProjectHandle->addSoftwareEnvironment(pUI->SoftEnvirTable->item(i,0)->text(),pUI->SoftEnvirTable->item(i,1)->text());
    }
    //Testify
    for(int i=0;i<pUI->TestDataList->rowCount();i++){
        mProjectHandle->addTestifyPath(pUI->TestDataList->item(i,1)->text());
    }
    //Supportive
    for(int i=0;i<pUI->SuportResList->rowCount();i++){
        mProjectHandle->addSupportive(pUI->SuportResList->item(i,1)->text());
    }

    //License
    mProjectHandle->setLicense(pUI->ChooseLicense->currentText());


    //save
    QString fileName = QFileDialog::getSaveFileName(pUI,
                                                    QObject::tr("Save Project"),
                                                    "",
                                                    QObject::tr("Xml Files (*.xml)"));

    if(!fileName.isEmpty()){
         mProjectHandle->SaveToFile(fileName);
    }


}

void MainWindow::keyPressEvent(QKeyEvent *e){
    //if (e->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier) && e->key() == Qt::Key_S)
    if (e->modifiers() == (Qt::ControlModifier) && e->key() == Qt::Key_S)
    {
        this->on_actionSave_Project_triggered();
    }
    if(e->modifiers() == (Qt::ControlModifier) && e->key() == Qt::Key_O){
        this->on_actionOpen_Mdl_triggered();
    }
    if(e->modifiers() == (Qt::ControlModifier) && e->key() == Qt::Key_P){
        this->on_actionBuild_Package_triggered();
    }
    if(e->modifiers() == (Qt::ControlModifier) && e->key() == Qt::Key_L){
        this->on_actionLoad_Project_triggered();
    }
}

void MainWindow::closeEvent(QCloseEvent *event)
{
     QMessageBox::StandardButton ExitButton;
     ExitButton=QMessageBox::question(this, tr("Exit"),
                                              QString(tr("Sure to exit?")),
                                              QMessageBox::Yes | QMessageBox::No);

    if(ExitButton==QMessageBox::No){
        event->ignore();
    }else if(ExitButton==QMessageBox::Yes){
        QMessageBox::StandardButton button;
        button = QMessageBox::question(this, tr("Save"),
                                             QString(tr("Save Project?")),
                                             QMessageBox::Yes | QMessageBox::No);
              if (button == QMessageBox::No) {
                  event->accept();
              }
              else if (button == QMessageBox::Yes) {
                 this->on_actionSave_Project_triggered();
                  event->accept();
              }
    }

}
